﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace sqxt
{
    public partial class follow : Form
    {
        public follow()
        {
            InitializeComponent();
        }
        public follow(string s)
        {
            
            hno = s;
            InitializeComponent();
        }
        string hno = "";
        SqlConnection conn = new SqlConnection(Dbconnect.s1);
        SqlCommand com;
        SqlDataAdapter sda;
        DataTable dt;
        private void follow_Load(object sender, EventArgs e)
        {
            try
            {
                string sql = "select followup_class 随访类型,next_followup_date 下次随访时间,real_followup_date 实际随访时间,complete 完成状态,followup_id,person_name from  vm_remind  where  person_healthfile_no='"+hno+"'";
                sda = new SqlDataAdapter(sql,conn);
                dt = new DataTable();
                sda.Fill(dt);
                bindingSource1.DataSource = dt;
                dataGridViewX1.DataSource = bindingSource1;
                dataGridViewX1.Columns["followup_id"].Visible = false;
                dataGridViewX1.Columns["person_name"].Visible = false;
                string name = dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells["person_name"].Value.ToString();
                this.Text = name+"的随访内容";
             
            }
            catch(Exception e1)
            {
                
            }

        }

        private void dataGridViewX1_DoubleClick(object sender, EventArgs e)
        {
            string folid = dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells["followup_id"].Value.ToString();
            string name=dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells["person_name"].Value.ToString();
            switch (dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[0].Value.ToString())
            {
                case "健康体检":
                    if (dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[3].Value.ToString() == "已完成")
                    {
                        bool chakan = true;
                        physical_check pf = new physical_check(hno,name,folid,chakan);
                        pf.Show();
                    }
                    else
                    {
                        physical_check pf = new physical_check(hno, name, folid);
                        pf.Show();
                    }

                    break;
                case "高血压患者随访":
                    if (dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[3].Value.ToString() == "已完成")
                    {
                        Hypertension_visit db_visit = new Hypertension_visit(folid);
                        db_visit.Show();
                    }
                    else
                    {
                        Hypertension_visit db_visit = new Hypertension_visit(name, hno, folid);
                        db_visit.Show();

                    }
                    break;
                case "2型糖尿病患者随访":
                    if (dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[3].Value.ToString() == "已完成")
                    {
                        diabete_visit db_visit = new diabete_visit(folid);
                        db_visit.Show();
                    }
                    else
                    {

                    }
                    break;
                case "老年人随访":
                    if (dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[3].Value.ToString() == "已完成")
                    {
                        bool chakan = true;
                        physical_check pf = new physical_check(hno, name, folid, chakan);
                        pf.Show();
                    }
                    else
                    {
                        string l = "老";
                        physical_check pf = new physical_check(hno, name, folid,l);
                        pf.Show();
                    }
                
                    break;
                case "孕产妇随访":
                    #region
                    conn.Open();
                    string dijici = "select count(*) from followup where  person_healthfile_no='" + hno + "'and followup_class='孕产妇随访'  and followup_id<='" + folid + "'";
                    SqlCommand cicom = new SqlCommand(dijici, conn);
                    int folci = (int)cicom.ExecuteScalar();//判断followup_id在什么位置
                    conn.Close();
                    if (dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[3].Value.ToString() == "已完成")
                    {

                        if (folci == 1)
                        {
                            bool b = true;
                            LactationWoman_visit1 lvs = new LactationWoman_visit1(folid, name, hno, b);
                            lvs.Show();
                        }
                        if (folci > 1 && folci < 6)//打开孕产妇随访表2用
                        {
                            string twofol = "";
                            conn.Open();
                            SqlCommand sc11 = new SqlCommand("select max(followup_id) from  followup where followup_id in(select top 2 followup_id  from followup where person_healthfile_no='" + hno + "' and real_followup_date is not  null  and  followup_class='孕产妇随访') ", conn);
                            SqlDataReader sdr11 = sc11.ExecuteReader();
                            sdr11.Read();
                            { twofol = sdr11[0].ToString(); }
                            conn.Close();
                            sdr11.Close();
                            bool b = true;
                            LactationWoman_visit2 lvs = new LactationWoman_visit2(folid,twofol, name, hno, b);
                            lvs.Show();
                        }
                        if (folci == 6)
                        {
                            bool b = true;
                            LactationWoman_visit3 lvs = new LactationWoman_visit3(folid, name, hno, b);
                            lvs.Show();
                        }


                    }
                    else
                    {
                        if (folci == 1)
                        {
                            LactationWoman_visit1 lvs = new LactationWoman_visit1(folid, name, hno);
                            lvs.Show();
                        }
                        if (folci > 1 && folci < 6)
                        {

                            string twofol = "";
                            conn.Open();
                            SqlCommand sc1 = new SqlCommand("select max(followup_id) from  followup where followup_id in(select top 2 followup_id  from followup where person_healthfile_no='" + hno + "' and real_followup_date is not  null  and  followup_class='孕产妇随访') ", conn);
                            SqlDataReader sdr1 = sc1.ExecuteReader();
                            sdr1.Read();
                            { twofol = sdr1[0].ToString(); }
                            conn.Close();
                            sdr1.Close();
                            bool b = true;
                            LactationWoman_visit2 lvs = new LactationWoman_visit2(folid, twofol, name, hno, b);
                            lvs.Show();
                        }

                        if (folci == 6)
                        {
                            LactationWoman_visit3 lvs = new LactationWoman_visit3(folid, name, hno);
                            lvs.Show();
                        }
                    }
                    #endregion
                    break;
                case "儿童随访":
                   
                    break;
                case "残疾人随访":
                    if (dataGridViewX1.Rows[dataGridViewX1.CurrentRow.Index].Cells[3].Value.ToString() == "已完成")
                    {
                        bool chakan = true;
                        physical_check pf = new physical_check(hno, name, folid, chakan);
                        pf.Show();
                    }
                    else
                    {
                        string s = "残";
                        physical_check pf = new physical_check(hno, name, folid,s);
                        pf.Show();
                    }
                    break;
            }

        }
    }
}